package com.salt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.salt.entity.IdleAffiliateCpaCommissionConfig;
import com.salt.mapper.IdleAffiliateCpaCommissionConfigMapper;
import com.salt.service.IdleAffiliateCpaCommissionConfigService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * 闲鱼联盟CPA佣金配置服务实现
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class IdleAffiliateCpaCommissionConfigServiceImpl extends ServiceImpl<IdleAffiliateCpaCommissionConfigMapper, IdleAffiliateCpaCommissionConfig> implements IdleAffiliateCpaCommissionConfigService {

    @Override
    public BigDecimal getCommissionAmount(Integer promotionType) {
        log.info("获取CPA佣金金额，推广类型：{}", promotionType);
        
        LambdaQueryWrapper<IdleAffiliateCpaCommissionConfig> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(IdleAffiliateCpaCommissionConfig::getPromotionType, promotionType)
               .eq(IdleAffiliateCpaCommissionConfig::getStatus, 1);
        
        IdleAffiliateCpaCommissionConfig config = getOne(wrapper);
        if (config == null) {
            log.warn("未找到对应的CPA佣金配置，推广类型：{}", promotionType);
            return BigDecimal.ZERO;
        }
        
        return config.getCommissionAmount();
    }
} 